//
//  CustomView.m
//  MasonryDemo
//
//  Created by hpkj on 2020/1/20.
//  Copyright © 2020 hpkj. All rights reserved.
//

#import "CustomView.h"
#import "Masonry.h"
@interface CustomView()
@property (nonatomic,strong) UIButton * btnTest;

@property (nonatomic,assign) int btnWidth;

@end

@implementation CustomView
-(instancetype)init
{
    self = [super init];
    if (self) {
        self.btnTest = [UIButton new];
        _btnTest.backgroundColor = [UIColor cyanColor];
        [self addSubview:_btnTest];
        
        _btnWidth = 100;
        
        [_btnTest addTarget:self action:@selector(clickAction) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return self;
}

+(BOOL)requiresConstraintBasedLayout
{
//    告诉UIKit系统，将使用AutoLayout来进行布局处理
    return YES;
}

//初始化时候会调用一次这个方法
- (void)updateConstraints
{
    
    
    [_btnTest mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@60);
        make.width.equalTo(@(_btnWidth));
        make.centerX.equalTo(self);
        make.height.equalTo(@79);
    }];
    

    
    [super updateConstraints];
    
}



-(void)clickAction
{
//    [_btnTest mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.width.equalTo(@160);
//    }];
    _btnWidth = 180;
    [self setNeedsUpdateConstraints];
}
@end

